package com.woniuxy.happylife;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.happylife.dao.RbacMenuDao;
import com.woniuxy.happylife.dao.RbacRoleDao;
import com.woniuxy.happylife.dto.AddRoleEntity;
import com.woniuxy.happylife.entity.RbacMenu;
import com.woniuxy.happylife.entity.RbacRole;
import com.woniuxy.happylife.entity.RbacRoleMenu;
import com.woniuxy.happylife.service.RbacMenuService;
import com.woniuxy.happylife.service.RbacRoleService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Title: test
 * @ProjectName: happy-life
 * @Description: TODO
 * @Author: chowinggum
 * @Date: 2022/2/18 11:37
 */
@SpringBootTest
public class test {
    @Autowired
    RbacMenuDao rbacMenuDao;
    @Autowired
    RbacRoleService rbacRoleService;
    @Autowired
    RbacRoleDao rbacRoleDao;
    @Autowired
    RbacMenuService rbacMenuService;
    @Autowired
    RedisTemplate redisTemplate;

    @Test
    public void test01(){
        List<RbacMenu> menus = rbacMenuDao.findByUsername("123");
        System.out.println(menus);
    }
    @Test
    public void test02(){
        List<RbacMenu> menus = rbacMenuService.findByUsername("123");
        System.out.println(menus);
    }
    @Test
    public void test03(){
        List<RbacRole> all = rbacRoleService.findAll();
        System.out.println(all);
    }
    @Test
    public void test05(){
//        PageHelper.startPage(formInLineEntity.getPage(),formInLineEntity.getLimit());
        List<RbacRole> roles =  rbacRoleService.findAll();
        PageInfo<RbacRole> rolePageInfo = new PageInfo<>(roles);
        System.out.println(rolePageInfo);
    }
    @Test
    public void test06(){
        rbacMenuService.findMenuByRoleId(1);
//        System.out.println(menuByRoleId);
    }
    @Test
    public void test07(){
        rbacMenuDao.deleteMenusByRoleId(4);
    }
    @Test
    public void test08(){
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("系统管理");
        list.add("商户管理");
        list.add("活动管理");
        list.add("权限管理");
        List<Integer> byMenuNames = rbacMenuDao.findByMenuNames(list);
        System.out.println(byMenuNames);
    }
    @Test
    public void test09(){
        List<RbacRoleMenu> list = new ArrayList<>();
        list.add(new RbacRoleMenu(4, 1));
        list.add(new RbacRoleMenu(4, 2));
        list.add(new RbacRoleMenu(4, 3));
        list.add(new RbacRoleMenu(4, 4));
        rbacMenuDao.addByRoleMenus(list);
    }
    @Test
    public void test10(){
        //测试loginout
        String token ="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1bmFtZSI6IjEyMyIsImlzcyI6ImphdmEiLCJleHAiOjE2NDU1MTIxMjEsImlhdCI6MTY0NTUxMDMyMX0.ScNzyVIfp-jU-eGqaMl21z9efy1mXAfFCXLIdJADMFA";
        Boolean token1 = redisTemplate.opsForHash().hasKey("token",token);
        Boolean tokencopy = redisTemplate.opsForHash().hasKey("tokencopy", token);
        System.out.println(token1);
        System.out.println(tokencopy);
    }
    @Test
    public void test11(){
        AddRoleEntity addRoleEntity=new AddRoleEntity();
        addRoleEntity.setName("aaa");
        List<String> list=new ArrayList<>();
        list.add("控制台");
        addRoleEntity.setData(list);

//        rbacRoleDao.addOne("aaa");
//        rbacRoleDao.addOne(addRoleEntity.getName());
        rbacRoleService.addOne(addRoleEntity);
    }
@Test
    public void test12(){
    RbacRole aaa = rbacRoleDao.findByName("aaa");
    System.out.println(aaa);

}
}
